www.gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\svm\kdist.m

    function [d, data2]=kdist(x,data,Alpha,ker,arg, data2)
% KDIST distance between vectors in a feature space.
% [d]=kdist(x,data,Alpha,ker,arg)
% [d]=kdist(x,data,Alpha,ker,arg, data2)
% 
% Computes distance between vectors Phi(x) and 
% sum( Alpha(i)*Phi(data(:,i))) in a feature space induced
% by a given kernel(a,b)=Phi(a)'*Phi(b).
%
% Inputs:
%  x [dim x l] the first vector(s) in the input space.
%  data [dim x n] data from the input space describing the second vector 
%   in the feture space.
%  Alpha [1 x n] weights of the data.
%  ker [string] kernel identifier; see help kernel.
%  arg [...] kernel argument.
% 
% Voluntary input:
%  data2 [real] Alpha'*kmatrix(data,ker,arg)*Alpha.
%
% Output:
%  d [1 x l] distance between in the feature space.
%  data2 [real] see above.
% 
 
% Modifications:
%  13-sep-2002, VF
%  15-jun-2002, VF

[dim,num]=size(x);

x2 = diag(kmatrix( x, ker, arg));

if nargin < 6,
  data2 = Alpha(:)'*kmatrix( data, ker, arg)*Alpha(:);
end

xdata = kmatrix( x, data, ker, arg);

d = sqrt(x2 - 2*xdata*Alpha(:) + repmat(data2,num,1) )';

return;